package com.myweather.android.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zcq
 * @package example.com.zcq.mymj.Adapter
 * @fileName MyMj
 * @description: 这个类的描述
 * @org 融信通达科技有限公司
 * @email @163.com
 * @date 2018/11/26  20:59
 */
public class TabPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private String[] tabNames;//tab选项名字
    private FragmentManager fm;

    public TabPageAdapter(FragmentManager fm, ArrayList<Fragment> fragments, String[] tabNames) {
        super(fm);
        this.fm = fm;
        this.fragments = fragments;
        this.tabNames = tabNames;

    }

    @Override
    public Fragment getItem(int i) {
        return fragments.get(i);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return tabNames[position];
    }

//    @NonNull
//    @Override
//    public Object instantiateItem(@NonNull ViewGroup container, int position) {
//        Fragment fragment = (Fragment) super.instantiateItem(container, position);
//        return fm.beginTransaction().show(fragment).commit();
//    }
//
//    @Override
//    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//        fm.beginTransaction().hide(fragments.get(position)).commit();
//    }
}